//
// Created by dong on 2025/10/21.
//

#ifndef BASEC_SMENUTWO_H
#define BASEC_SMENUTWO_H
#include "SWidget.h"
#include "demo101.h"
#include "SActionTwo.h"

class SMenuTwo:public Swidget
{
public:
    SMenuTwo(Swidget* parent=nullptr);
    SMenuTwo(const string& str,Swidget* parent = nullptr);
    SActionTwo* addAction(const string& text);
    SActionTwo* addAction(SActionTwo* act);
    template<typename pr,typename ...Args>
    void connect(const string& text,pr&& f,Args&& ...args)
    {
        int pos = -1;
        for (int i=0;i<m_action.size();i++)
        {
            if (m_action[i]->text() ==text)
            {
                pos=i;
                break;
            }
        }
        if (pos!=-1)
        {
            m_action[pos]->connect(f,args...);
        }
    }
public:
    void paintEvent(SDL_Event* msg) override;
    void mousePressEvent(SDL_Event* msg) override;
    void mouseMoveEvent(SDL_Event* msg) override;
    void paintAction(SDL_Event* mgs);
    int getId(int x,int y);
protected:
    vector<unique_ptr<SActionTwo>> m_action;
    string m_text;
    bool actionVisible;

};


#endif //BASEC_SMENUTWO_H